home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Using a Cached Bitmap to Improve Performance / GDITEST45.dpr
Encoding:
Text File  |  2003-10-15  |  3.1 KB  |  126 lines

  1. program GDITEST45;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   bitmap   : TGPBitmap;
  14.   Font: TGPFont;
  15.   Brush: TGPSolidBrush;
  16.   width, height: Integer;
  17.   cBitmap: TGPCachedBitmap;
  18.   j: integer;
  19.   T1, T2: TDateTime;
  20.   h,m,s, ms: word;
  21. begin
  22.   graphics := TGPGraphics.Create(DC);
  23.  
  24.   bitmap := TGPBitmap.Create('..\..\Media\Fruit.JPG');
  25.   width  := bitmap.GetWidth;
  26.   height := bitmap.GetHeight;
  27.   cBitmap:= TGPCachedBitmap.Create(bitmap, graphics);
  28.   Font:= TGPFont.Create('Arial',16);
  29.   Brush:= TGPSolidBrush.Create(aclBlack);
  30.  
  31.   j := 0;
  32.   T1 := now;
  33.   While j < 300 do
  34.   begin
  35.     graphics.DrawImage(bitmap, j, j div 2, width, height);
  36.     inc(j,10)
  37.   end;
  38.   T2 := now;
  39.   DecodeTime(T2-T1,h,m,s,ms);
  40.   graphics.DrawString(IntTostr(s) +':'+ IntTostr(ms),-1,Font,MakePoint(j+width,(j/2)),Brush);
  41.  
  42.   j := 0;
  43.   T1 := now;
  44.   While j < 300 do
  45.   begin
  46.     graphics.DrawCachedBitmap(cBitmap, j, 150 + j div 2 );
  47.     inc(j,10);
  48.   end;
  49.   T2 := now;
  50.   DecodeTime(T2-T1,h,m,s,ms);
  51.   graphics.DrawString(IntTostr(s) +':'+ IntTostr(ms),-1,Font,MakePoint(j+width,(j/2)+150),Brush);
  52.  
  53.   Brush.Free;
  54.   Font.Free;
  55.   graphics.Free;
  56.   bitmap.Free;
  57.   cBitmap.Free;
  58. end;
  59.  
  60.  
  61. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  62. var
  63.   Handle: HDC;
  64.   ps: PAINTSTRUCT;
  65. begin
  66.   case message of
  67.     WM_PAINT:
  68.       begin
  69.         Handle := BeginPaint(Wnd, ps);
  70.         OnPaint(Handle);
  71.         EndPaint(Wnd, ps);
  72.         result := 0;
  73.       end;
  74.  
  75.     WM_DESTROY:
  76.       begin
  77.         PostQuitMessage(0);
  78.         result := 0;
  79.       end;
  80.  
  81.    else
  82.       result := DefWindowProc(Wnd, message, wParam, lParam);
  83.    end;
  84. end;
  85.  
  86. var
  87.   hWnd     : THandle;
  88.   Msg      : TMsg;
  89.   wndClass : TWndClass;
  90. begin
  91.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  92.    wndClass.lpfnWndProc    := @WndProc;
  93.    wndClass.cbClsExtra     := 0;
  94.    wndClass.cbWndExtra     := 0;
  95.    wndClass.hInstance      := hInstance;
  96.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  97.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  98.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  99.    wndClass.lpszMenuName   := nil;
  100.    wndClass.lpszClassName  := 'GettingStarted';
  101.  
  102.    RegisterClass(wndClass);
  103.  
  104.    hWnd := CreateWindow(
  105.       'GettingStarted',       // window class name
  106.       'Using a Cached Bitmap to Improve Performance',       // window caption
  107.       WS_OVERLAPPEDWINDOW,    // window style
  108.       Integer(CW_USEDEFAULT), // initial x position
  109.       Integer(CW_USEDEFAULT), // initial y position
  110.       Integer(CW_USEDEFAULT), // initial x size
  111.       Integer(CW_USEDEFAULT), // initial y size
  112.       0,                      // parent window handle
  113.       0,                      // window menu handle
  114.       hInstance,              // program instance handle
  115.       nil);                   // creation parameters
  116.  
  117.    ShowWindow(hWnd, SW_SHOW);
  118.    UpdateWindow(hWnd);
  119.  
  120.    while(GetMessage(msg, 0, 0, 0)) do
  121.    begin
  122.       TranslateMessage(msg);
  123.       DispatchMessage(msg);
  124.    end;
  125. end.
  126.